<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use app\admin\model\Role;
use app\admin\model\Backs;
use app\admin\model\Node;
use app\constant\rbac;
class Permiss extends Controller{
   //角色列表
   public function role(){
   	  $role=Role::getInformationAll(['status'=>1]);
   	  $this->assign('role_list',json_encode($role,true));
      return $this->fetch();
   }
   //角色添加
   public function roleadd(){
      return $this->fetch();
   }

    //角色授权
   public function roleaccess(){
   	  $input=request()->param();
   	  $allrole=Role::getInformationAll(['status'=>1]);
      $user=Backs::getInformationAll(['status'=>1]);
   	  $this->assign([
            'user'=>json_encode(isset($user)?$user:null),
            'allrole'=>json_encode($allrole?$allrole:null),
            'session_user'=>json_encode(session('back_user')),
   	  	]);
      return $this->fetch();
   }
   //角色修改
   public function updateroleaccess(){
       $input=request()->param();
        if(isset($input['id'])){
           //获取当前用户的信息和所属角色
           $user=Backs::getInformation(['id'=>$input['id']]);
           $user && $role=Role::getUserRole($input['id']);
        }
      $allrole=Role::getInformationAll(['status'=>1]);
      $this->assign([
            'user'=>json_encode(isset($user)?$user:null),
            'role'=>json_encode(isset($role)?$role:null),
            'allrole'=>json_encode($allrole?$allrole:null),
            'session_user'=>json_encode(session('back_user')),
        ]);
       return $this->fetch();
   }

   //管理员列表
   public function userlist(){
   	 $role=Backs::getInformationAll(['status'=>1]);
   	 $this->assign('user',json_encode($role,true));
   	 return $this->fetch();
   }

   //节点动作列表
   public function nodelist(){
   	 $role=Node::getInformationAll(['status'=>1]);
       $this->assign('role_list',json_encode($role,true));
   	 $this->assign('LEVEL',json_encode(rbac\LEVEL_NODE_VALUE,true));
   	 return $this->fetch();
   }
   //节点添加
   public function nodeadd(){
   	 return $this->fetch();
   }

   public function test1(){
      if(request()->isPost()){
            // echo "test 1 Action";
         return "test 1 Action";
      }else{
         return $this->fetch('set');
      }
      // dump(request()->isPost());
      //  return "test 1 Action";
   }
   public function test2(){
      if(request()->isPost()){
            echo "test 2 Action";
      }else{
          return $this->fetch('set');
      }
   }
   public function test3(){
      dump(request()->isPost());
   }
}